//
//  SYZiYuanFaFangDateView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/5/22.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYZiYuanFaFangDateView.h"
#import "CJYearMonthSelectedView.h"
#import "BRDatePickerView.h"


@interface SYZiYuanFaFangDateView ()
@property (weak, nonatomic) IBOutlet UIButton *fafangBtn;
@property (weak, nonatomic) IBOutlet UIButton *huishouBtn;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end


@implementation SYZiYuanFaFangDateView


- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 5;
    
    _fafangBtn.layer.borderColor = [UIColor colorWithHexString:@"#999999"].CGColor;
    _fafangBtn.layer.borderWidth = 1;
    
    _huishouBtn.layer.borderColor = [UIColor colorWithHexString:@"#999999"].CGColor;
    _huishouBtn.layer.borderWidth = 1;
    
    
}

- (IBAction)cancelBtnClick:(UIButton *)sender {
    
    [self removeFromSuperview];
}


- (IBAction)quedingBtn:(UIButton *)sender {
    
    NSString *fafang = self.fafangBtn.titleLabel.text;
    NSString *huishou = self.huishouBtn.titleLabel.text;
    if (fafang.length == 0) {
        [MBProgressHUD zr_showError:@"请选择发放日期"];
        return;
    }
    
    if (huishou.length == 0) {
        [MBProgressHUD zr_showError:@"请选择回收日期"];
        return;
    }
    
    if (self.block) {
        self.block(fafang, huishou);
    }
    [self removeFromSuperview];
}

- (IBAction)dateBtnClick:(UIButton *)sender {
    NSDate *minDate = [NSDate br_setYear:2030 month:3 day:12];
    NSDate *maxDate = [NSDate date];
    NSString *title = nil;
    
    if (sender.tag == 100) {//发放
        title = @"请选择发放日期";
    } else {
        title = @"请选择回收日期";
    }
    __weak typeof(self) weakSelf = self;
    [BRDatePickerView showDatePickerWithTitle:title dateType:BRDatePickerModeYMD defaultSelValue:nil minDate:maxDate maxDate:minDate isAutoSelect:YES themeColor:[UIColor colorWithHexString:@"#20B097"] view:sender resultBlock:^(NSString *selectValue) {
        
        if (sender.tag == 100) {
            [weakSelf.fafangBtn setTitle:selectValue forState:UIControlStateNormal];
        } else {
            [weakSelf.huishouBtn setTitle:selectValue forState:UIControlStateNormal];
        }
        
    } cancelBlock:^{
        
    }];
    
    
    
    
}


@end
